package org.example.design.visitor.test1;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.Iterator;


/**
 * @author huangshen
 * @version 0
 * @description Director
 * @since 2022/2/9 21:45
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class Directory extends Entry {

    private String name;

    private ArrayList dir = new ArrayList();

    public Directory(String name) {
        this.name = name;
    }

    @Override
    public Iterator iterator() {
        return dir.iterator();
    }

    @Override
    public Entry add(Entry entry) {
        dir.add(entry);
        return this;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getSize() {
        int size = 0;
        for (Object o : dir) {
            Entry entry = (Entry) o;
            size += entry.getSize();
        }
        return size;
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(this);
    }

    @Override
    public String toString() {
        return getName() + "(" + getSize() + ")" ;
    }
}
